// pagesProperty/pages/asset/check/list/index.js
var app = getApp(), fetchApi = require("../../../../../utils/httpPost.js"),
formatTime = require("../../../../../component/common.js");
import Toast from '../../../../../component/vant/toast/toast';
import Dialog from '../../../../../component/vant/dialog/dialog';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isLoading: true,
    hasData: false,
    pageIndex: 1,
    pageSize: 10,
    assetList:[],
    checkState:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.onHttpInit();
  },  
  handleChange({detail}){    
    console.log('detail',detail)
    this.data.pageIndex = 1;
    this.setData({
      assetList : [],
      currentTab: detail.index
    })
    this.data.checkState = detail.index;
    this.onHttpInit();
  },
  onHttpInit: function () {
    var that = this;
    fetchApi.httpPost('/estate/asset/list', {
      pageIndex: that.data.pageIndex,
      pageSize: that.data.pageSize,
      checkState: that.data.checkState,
      asset_type:0,
    }, function (res) {
      console.log("获取资产信息", res)
      if (res.data.code == 0) {
        var assetList = res.data.data.assetList;
        if(assetList.length > 0){
          that.data.pageIndex += 1;
          for (var index in assetList) {
            that.data.assetList.splice(that.data.assetList.length, 0, assetList[index]);
          }
          that.setData({
            hasData: true,
            assetList: that.data.assetList
          })
        }
      }else{
        // Toast.fail(res.data.msg)
      }
      // complete
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
      that.setData({ netWork: true,loading: true,  isLoading: false, })
    }, function () {
      that.setData({ netWork: false, hasData: false,loading: true,  isLoading: false, })
    })
  },
  goDetail(e){
    var assetId = e.currentTarget.dataset.item.id;
    wx.navigateTo({
      url: '../index?id=' + assetId+'&from=click',
    })
  },
  onPullDownRefresh: function () {
    this.data.pageIndex = 1;
    this.setData({
      isLoading:true,
      assetList:[],
    })
    this.onHttpInit();
  },
  /**
   * 页面上拉触底事件的处理函数    加载更多
   */
  onReachBottom: function () {
    this.onHttpInit();
  },
})